#pragma once

#include "functor.h"


namespace el
{
	typedef unsigned long TTime;

	class Timer
	{
	public:
		Timer(const Functor& cb, TTime when, TTime interval)
			: cb_(cb), expiration_(when), interval_(interval), repeat_(interval > 0) {}
		void run() { cb_(); }

		TTime expiration() const { return expiration_; }
		bool repeat() const { return repeat_; }
		void restart(TTime now)
		{
			if (repeat_) expiration_ = now + interval_;
			else expiration_ = 0;
		}

	private:
		Functor cb_;
		TTime expiration_;
		TTime interval_;
		bool repeat_;
	};
}